    //
//  WallpaperViewController.m
//  SmartRoadShow
//
//  Created by Tracy E on 10-9-19.
//  Copyright 2010 simonwang142232@gmail.com. All rights reserved.
//

#import "WallpaperViewController.h"


@implementation WallpaperViewController


- (id)init {
    if (self = [super init]) {
		self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
		
	    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
		[imageView setContentMode:UIViewContentModeScaleToFill];
		[self.view addSubview:imageView];
		[imageView release];
		
		sheet = [[UIActionSheet alloc] initWithTitle:@"smart壁纸预览" delegate:self
								   cancelButtonTitle:@"取消" destructiveButtonTitle:@"下载"
								   otherButtonTitles:nil];
		
		sheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
		[sheet showInView:self.view];
		[sheet release];
	}
    return self;
}

- (void)sendImage:(NSInteger) index{
	image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",index + 1]];
	[imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%d.jpg",index + 1]]];
}


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
	//将图片设为壁纸
	if (buttonIndex == 0) {
		UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"保存成功!"
														message:@"图片已经存入图片库，请到设置里面将该图片设为壁纸！"
													   delegate:self
											  cancelButtonTitle:@"确定"
											  otherButtonTitles:nil];
		[alert show];
		[alert release];
	}
	else {
		[self dismissModalViewControllerAnimated:YES];
	}
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
	[self dismissModalViewControllerAnimated:YES];
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
